package org.idea.spring.datasource.ibernate.config;

import org.idea.spring.datasource.ibernate.factorybean.UserMapperFactoryBean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @Author linhao
 * @Date created in 4:15 下午 2021/5/17
 */
@Component
public class IbernateBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
        System.out.println("genericBeanDefinition is : " + genericBeanDefinition);
        genericBeanDefinition.setBeanClass(UserMapperFactoryBean.class);
        DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory;
        defaultListableBeanFactory.registerBeanDefinition("userDao",genericBeanDefinition);
    }
}
